package com.bat.controller;

import com.bat.feign.TestFeign;
import com.bat.feign.vo.res.TestResVo;
import com.bat.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @program: eureka-server
 * @description:
 * @author: zhoupengfei
 * @create: 2019-09-12 16:20
 **/
@RestController
@RefreshScope
@Slf4j
@Api(tags = "测试")
@Data
public class NacosHomeController implements TestFeign {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Value("${test:默认值}")
    private String nacosConf;

    @ApiOperation("首页")
    @GetMapping("/index")
    public R index(){
        return R.s();
    }

    @GetMapping("/nacosConf")
    @ApiOperation("nacos配置测试")
    public R<String> nacosConf(){
        return R.s(nacosConf);
    }

    @Override
    public R<TestResVo> testFeign() {
        return R.s(TestResVo.builder().date(new Date()).build());
    }

    @GetMapping("/mqSend")
    @ApiOperation("mq发送消息测试")
    public R<String> mqSend(String msg){
        rocketMQTemplate.sendOneWay("topic",msg);
        return R.s(msg);
    }

}